home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 1 / The Arsenal Files (Arsenal Computer).ISO / archive / unixarc.pt3 / text0000.txt < prev   
Encoding:
Text File  |  1994-01-23  |  62.0 KB  |  2,143 lines

  1. Submitted-by: hyc@math.lsa.umich.edu
  2. Posting-number: Volume 15, Issue 79
  3. Archive-name: arc5.21/part03
  4.  
  5. #--------------------------------CUT HERE-------------------------------------
  6. #! /bin/sh
  7. #
  8. # This is a shell archive.  Save this into a file, edit it
  9. # and delete all lines above this comment.  Then give this
  10. # file to sh by executing the command "sh file".  The files
  11. # will be extracted into the current directory owned by
  12. # you with default permissions.
  13. #
  14. # The files contained herein are:
  15. #
  16. # -rw-r--r--  1 hyc         11146 Jun 17 17:03 arc.c
  17. # -rw-r--r--  1 hyc          3318 Jun  1 19:59 arc.h
  18. # -rw-r--r--  1 hyc          9286 Jun 13 00:31 arcadd.c
  19. # -rw-r--r--  1 hyc          1204 Jun  1 15:16 arccode.c
  20. # -rw-r--r--  1 hyc          3396 Jun  1 19:18 arccvt.c
  21. # -rw-r--r--  1 hyc          2070 Jun 13 04:26 arcdata.c
  22. # -rw-r--r--  1 hyc          2055 Apr 19 01:39 arcdel.c
  23. # -rw-r--r--  1 hyc          5008 Jun 13 14:08 arcdos.c
  24. # -rw-r--r--  1 hyc          4898 Jun 13 14:06 arcext.c
  25. # -rw-r--r--  1 hyc          7418 Jun 13 13:48 arcio.c
  26. # -rw-r--r--  1 hyc          4418 Jun  1 18:06 arclst.c
  27. #
  28. echo 'x - arc.c'
  29. if test -f arc.c; then echo 'shar: not overwriting arc.c'; else
  30. sed 's/^X//' << '________This_Is_The_END________' > arc.c
  31. X/*
  32. X * $Header: arc.c,v 1.10 88/06/17 15:22:48 hyc Locked $
  33. X */
  34. X
  35. X/*  ARC - Archive utility
  36. X  
  37. X    Version 5.21, created on 04/22/87 at 15:05:21
  38. X  
  39. X(C) COPYRIGHT 1985-87 by System Enhancement Associates; ALL RIGHTS RESERVED
  40. X  
  41. X    By:     Thom Henderson
  42. X  
  43. X    Description:
  44. X     This program is a general archive utility, and is used to maintain
  45. X     an archive of files.  An "archive" is a single file that combines
  46. X     many files, reducing storage space and allowing multiple files to
  47. X     be handled as one.
  48. X  
  49. X    Instructions:
  50. X     Run this program with no arguments for complete instructions.
  51. X  
  52. X    Programming notes:
  53. X     ARC Version 2 differs from version 1 in that archive entries
  54. X     are automatically compressed when they are added to the archive,
  55. X     making a separate compression step unecessary.     The nature of the
  56. X     compression is indicated by the header version number placed in
  57. X     each archive entry, as follows:
  58. X  
  59. X     1 = Old style, no compression
  60. X     2 = New style, no compression
  61. X     3 = Compression of repeated characters only
  62. X     4 = Compression of repeated characters plus Huffman SQueezing
  63. X     5 = Lempel-Zev packing of repeated strings (old style)
  64. X     6 = Lempel-Zev packing of repeated strings (new style)
  65. X     7 = Lempel-Zev Williams packing with improved hash function
  66. X     8 = Dynamic Lempel-Zev packing with adaptive reset
  67. X     9 = Dynamic Lempel-Zev packing, larger hash table
  68. X  
  69. X     Type 5, Lempel-Zev packing, was added as of version 4.0
  70. X  
  71. X     Type 6 is Lempel-Zev packing where runs of repeated characters
  72. X     have been collapsed, and was added as of version 4.1
  73. X  
  74. X     Type 7 is a variation of Lempel-Zev using a different hash
  75. X     function which yields speed improvements of 20-25%, and was
  76. X     added as of version 4.6
  77. X  
  78. X     Type 8 is a different implementation of Lempel-Zev, using a
  79. X     variable code size and an adaptive block reset, and was added
  80. X     as of version 5.0
  81. X  
  82. X     Type 9 is a slight modification of type 8, first used by Phil
  83. X     Katz in his PKARC utilites. The primary difference is the use
  84. X     of a hash table twice as large as for type 8, and that this
  85. X     algorithm called Squashing, doesn't perform run-length encoding
  86. X     on the input data.
  87. X  
  88. X     Verion 4.3 introduced a temporary file for holding the result
  89. X     of the first crunch pass, thus speeding up crunching.
  90. X  
  91. X     Version 4.4 introduced the ARCTEMP environment string, so that
  92. X     the temporary crunch file may be placed on a ramdisk.    Also
  93. X     added was the distinction bewteen Adding a file in all cases,
  94. X     and Updating a file only if the disk file is newer than the
  95. X     corresponding archive entry.
  96. X  
  97. X     The compression method to use is determined when the file is
  98. X     added, based on whichever method yields the smallest result.
  99. X  
  100. X    Language:
  101. X     Computer Innovations Optimizing C86
  102. X*/
  103. X#include <stdio.h>
  104. X#include "arc.h"
  105. X
  106. Xint        strlen();
  107. Xvoid        addarc(), delarc(), extarc(), lstarc(), tstarc(), cvtarc(), runarc();
  108. Xvoid        abort();
  109. X#if    MTS
  110. Xvoid        etoa();
  111. X#endif
  112. X#if    GEMDOS
  113. Xlong        _stksize = 24576;
  114. X#endif
  115. Xchar        *strcpy(), *strcat();
  116. X
  117. Xstatic char   **lst;        /* files list */
  118. Xstatic int    lnum;        /* length of files list */
  119. X
  120. Xmain(num, arg)            /* system entry point */
  121. X    int        num;    /* number of arguments */
  122. X    char           *arg[];    /* pointers to arguments */
  123. X{
  124. X    char        opt = 0;/* selected action */
  125. X    char           *a;    /* option pointer */
  126. X    char           *makefnam();    /* filename fixup routine */
  127. X    void        upper();/* case conversion routine */
  128. X    char           *index();/* string index utility */
  129. X    char           *envfind();    /* environment searcher */
  130. X    int        n;    /* index */
  131. X    char           *arctemp2, *calloc(), *mktemp();
  132. X#if    GEMDOS
  133. X    void        exitpause();
  134. X#endif
  135. X#if    MTS
  136. X    fortran void    guinfo();
  137. X    char        gotinf[4];
  138. X#endif
  139. X
  140. X    if (num < 3) {
  141. X        printf("ARC - Archive utility, Version 5.21, created on 04/22/87 at 15:05:21\n");
  142. X/*        printf("(C) COPYRIGHT 1985,86,87 by System Enhancement Associates;");
  143. X        printf(" ALL RIGHTS RESERVED\n\n");
  144. X        printf("Please refer all inquiries to:\n\n");
  145. X        printf("       System Enhancement Associates\n");
  146. X        printf("       21 New Street, Wayne NJ 07470\n\n");
  147. X        printf("You may copy and distribute this program freely,");
  148. X        printf(" provided that:\n");
  149. X        printf("    1)     No fee is charged for such copying and");
  150. X        printf(" distribution, and\n");
  151. X        printf("    2)     It is distributed ONLY in its original,");
  152. X        printf(" unmodified state.\n\n");
  153. X        printf("If you like this program, and find it of use, then your");
  154. X        printf(" contribution will\n");
  155. X        printf("be appreciated.     You may not use this product in a");
  156. X        printf(" commercial environment\n");
  157. X        printf("or a governmental organization without paying a license");
  158. X        printf(" fee of $35.  Site\n");
  159. X        printf("licenses and commercial distribution licenses are");
  160. X        printf(" available.  A program\n");
  161. X        printf("disk and printed documentation are available for $50.\n");
  162. X        printf("\nIf you fail to abide by the terms of this license, ");
  163. X        printf(" then your conscience\n");
  164. X        printf("will haunt you for the rest of your life.\n\n"); */
  165. X#if    MSDOS
  166. X        printf("Usage: ARC {amufdxerplvtc}[bswnoq][g<password>]");
  167. X#endif
  168. X#if    GEMDOS
  169. X        printf("Usage: ARC {amufdxerplvtc}[bhswnoq][g<password>]");
  170. X#endif
  171. X#if    UNIX
  172. X        printf("Usage: arc {amufdxerplvtc}[biswnoq][g<password>]");
  173. X#endif
  174. X#if    MTS
  175. X        printf("Parameters: {amufdxeplvtc}[biswnoq][g<password>]");
  176. X#endif
  177. X        printf(" <archive> [<filename> . . .]\n");
  178. X        printf("Where:     a   = add files to archive\n");
  179. X        printf("     m   = move files to archive\n");
  180. X        printf("     u   = update files in archive\n");
  181. X        printf("     f   = freshen files in archive\n");
  182. X        printf("     d   = delete files from archive\n");
  183. X        printf("     x,e = extract files from archive\n");
  184. X#if    !MTS
  185. X        printf("     r   = run files from archive\n");
  186. X#endif
  187. X        printf("     p   = copy files from archive to");
  188. X        printf(" standard output\n");
  189. X        printf("     l   = list files in archive\n");
  190. X        printf("     v   = verbose listing of files in archive\n");
  191. X        printf("     t   = test archive integrity\n");
  192. X        printf("     c   = convert entry to new packing method\n");
  193. X        printf("     b   = retain backup copy of archive\n");
  194. X#if    GEMDOS
  195. X        printf("     h   = hold screen after finishing\n");
  196. X#endif
  197. X#if    MTS
  198. X        printf("     i   = suppress ASCII/EBCDIC translation\n");
  199. X#endif
  200. X#if    UNIX
  201. X        printf("     i   = suppress image mode (translate EOL)\n");
  202. X#endif
  203. X        printf("     s   = suppress compression (store only)\n");
  204. X        printf("     w   = suppress warning messages\n");
  205. X        printf("     n   = suppress notes and comments\n");
  206. X        printf("     o   = overwrite existing files when");
  207. X        printf(" extracting\n");
  208. X        printf("     q   = squash instead of crunching\n");
  209. X        printf("     g   = Encrypt/decrypt archive entry\n");
  210. X        printf("\nAdapted from MSDOS by Howard Chu\n");
  211. X        /*
  212. X         * printf("\nPlease refer to the program documentation for");
  213. X         * printf(" complete instructions.\n"); 
  214. X         */
  215. X#if    GEMDOS
  216. X        exitpause();
  217. X#endif
  218. X        return 1;
  219. X    }
  220. X    /* see where temp files go */
  221. X#if    !MTS
  222. X    arctemp = calloc(1, STRLEN);
  223. X    if (!(arctemp2 = envfind("ARCTEMP")))
  224. X        arctemp2 = envfind("TMPDIR");
  225. X    if (arctemp2) {
  226. X        strcpy(arctemp, arctemp2);
  227. X        n = strlen(arctemp);
  228. X        if (arctemp[n - 1] != CUTOFF)
  229. X            arctemp[n] = CUTOFF;
  230. X    }
  231. X#if    !MSDOS
  232. X    strcat(arctemp, mktemp("AXXXXXX"));
  233. X#else
  234. X    strcat(arctemp, "$ARCTEMP");
  235. X#endif
  236. X#else
  237. X    guinfo("SHFSEP    ", gotinf);
  238. X    sepchr[0] = gotinf[0];
  239. X    guinfo("SCRFCHAR", gotinf);
  240. X    tmpchr[0] = gotinf[0];
  241. X    arctemp = "-$$$";
  242. X    arctemp[0] = tmpchr[0];
  243. X#endif
  244. X
  245. X#if    !UNIX
  246. X    /* avoid any case problems with arguments */
  247. X
  248. X    for (n = 1; n < num; n++)    /* for each argument */
  249. X        upper(arg[n]);    /* convert it to uppercase */
  250. X#else
  251. X    /* avoid case problems with command options */
  252. X    upper(arg[1]);        /* convert to uppercase */
  253. X#endif
  254. X
  255. X    /* create archive names, supplying defaults */
  256. X    makefnam(arg[2], ".arc", arcname);
  257. X    /* makefnam(".$$$",arcname,newname); */
  258. X    sprintf(newname, "%s.arc", arctemp);
  259. X    makefnam(".BAK", arcname, bakname);
  260. X
  261. X    /* now scan the command and see what we are to do */
  262. X
  263. X    for (a = arg[1]; *a; a++) {    /* scan the option flags */
  264. X#if    !MTS
  265. X        if (index("AMUFDXEPLVTCR", *a)) {    /* if a known command */
  266. X#else
  267. X        if (index("AMUFDXEPLVTC", *a)) {
  268. X#endif
  269. X            if (opt)/* do we have one yet? */
  270. X                abort("Cannot mix %c and %c", opt, *a);
  271. X            opt = *a;    /* else remember it */
  272. X        } else if (*a == 'B')    /* retain backup copy */
  273. X            keepbak = 1;
  274. X
  275. X        else if (*a == 'W')    /* suppress warnings */
  276. X            warn = 0;
  277. X#if    !DOS
  278. X        else if (*a == 'I')    /* image mode, no ASCII/EBCDIC x-late */
  279. X            image = !image;
  280. X#endif
  281. X#if    GEMDOS
  282. X        else if (*a == 'H')    /* pause before exit */
  283. X            hold = 1;
  284. X#endif
  285. X
  286. X        else if (*a == 'N')    /* suppress notes and comments */
  287. X            note = 0;
  288. X
  289. X        else if (*a == 'O')    /* overwrite file on extract */
  290. X            overlay = 1;
  291. X
  292. X        else if (*a == 'G') {    /* garble */
  293. X            password = a + 1;
  294. X            while (*a)
  295. X                a++;
  296. X            a--;
  297. X#if    MTS
  298. X            etoa(password, strlen(password));
  299. X#endif
  300. X        } else if (*a == 'S')    /* storage kludge */
  301. X            nocomp = 1;
  302. X
  303. X        else if (*a == 'K')    /* special kludge */
  304. X            kludge = 1;
  305. X
  306. X        else if (*a == 'Q')    /* use squashing */
  307. X            dosquash = 1;
  308. X
  309. X        else if (*a == '-' || *a == '/')    /* UNIX and PC-DOS
  310. X                             * option markers */
  311. X            ;
  312. X
  313. X        else
  314. X            abort("%c is an unknown command", *a);
  315. X    }
  316. X
  317. X    if (!opt)
  318. X        abort("I have nothing to do!");
  319. X
  320. X    /* get the files list set up */
  321. X
  322. X    lnum = num - 3;        /* initial length of list */
  323. X    lst = (char **) calloc((lnum==0) ? 1:lnum,
  324. X                 sizeof(char *));    /* initial list */
  325. X    for (n = 3; n < num; n++)
  326. X        lst[n - 3] = arg[n];
  327. X
  328. X    for (n = 0; n < lnum;) {/* expand indirect references */
  329. X        if (*lst[n] == '@')
  330. X            expandlst(n);
  331. X        else
  332. X            n++;
  333. X    }
  334. X
  335. X    /* act on whatever action command was given */
  336. X
  337. X    switch (opt) {        /* action depends on command */
  338. X    case 'A':        /* Add */
  339. X    case 'M':        /* Move */
  340. X    case 'U':        /* Update */
  341. X    case 'F':        /* Freshen */
  342. X        addarc(lnum, lst, (opt == 'M'), (opt == 'U'), (opt == 'F'));
  343. X        break;
  344. X
  345. X    case 'D':        /* Delete */
  346. X        delarc(lnum, lst);
  347. X        break;
  348. X
  349. X    case 'E':        /* Extract */
  350. X    case 'X':        /* eXtract */
  351. X    case 'P':        /* Print */
  352. X        extarc(lnum, lst, (opt == 'P'));
  353. X        break;
  354. X
  355. X    case 'V':        /* Verbose list */
  356. X        bose = 1;
  357. X    case 'L':        /* List */
  358. X        lstarc(lnum, lst);
  359. X        break;
  360. X
  361. X    case 'T':        /* Test */
  362. X        tstarc();
  363. X        break;
  364. X
  365. X    case 'C':        /* Convert */
  366. X        cvtarc(lnum, lst);
  367. X        break;
  368. X#if    !MTS
  369. X    case 'R':        /* Run */
  370. X        runarc(lnum, lst);
  371. X        break;
  372. X#endif
  373. X    default:
  374. X        abort("I don't know how to do %c yet!", opt);
  375. X    }
  376. X#if    GEMDOS
  377. X    if (hold)
  378. X        exitpause();
  379. X#endif
  380. X    return nerrs;
  381. X}
  382. Xstatic
  383. Xexpandlst(n)            /* expand an indirect reference */
  384. X    int        n;    /* number of entry to expand */
  385. X{
  386. X    FILE           *lf, *fopen();    /* list file, opener */
  387. X    char           *malloc(), *realloc();    /* memory managers */
  388. X    char        buf[100];    /* input buffer */
  389. X    int        x;    /* index */
  390. X    char           *p = lst[n] + 1; /* filename pointer */
  391. X
  392. X    if (*p) {        /* use name if one was given */
  393. X        makefnam(p, ".CMD", buf);
  394. X        if (!(lf = fopen(buf, "r")))
  395. X            abort("Cannot read list of files in %s", buf);
  396. X    } else
  397. X        lf = stdin;    /* else use standard input */
  398. X
  399. X    for (x = n + 1; x < lnum; x++)    /* drop reference from the list */
  400. X        lst[x - 1] = lst[x];
  401. X    lnum--;
  402. X
  403. X    while (fscanf(lf, "%99s", buf) > 0) {    /* read in the list */
  404. X        if (!(lst =(char **)realloc(lst, (lnum + 1) * sizeof(char *))))
  405. X            abort("too many file references");
  406. X
  407. X        lst[lnum] = malloc(strlen(buf) + 1);
  408. X        strcpy(lst[lnum], buf); /* save the name */
  409. X        lnum++;
  410. X    }
  411. X
  412. X    if (lf != stdin)    /* avoid closing standard input */
  413. X        fclose(lf);
  414. X}
  415. ________This_Is_The_END________
  416. if test `wc -c < arc.c` -ne    11146; then
  417.     echo 'shar: arc.c was damaged during transit (should have been    11146 bytes)'
  418. fi
  419. fi        ; : end of overwriting check
  420. echo 'x - arc.h'
  421. if test -f arc.h; then echo 'shar: not overwriting arc.h'; else
  422. sed 's/^X//' << '________This_Is_The_END________' > arc.h
  423. X/*
  424. X * $Header: arc.h,v 1.7 88/06/01 17:51:06 hyc Locked $
  425. X */
  426. X
  427. X#undef    MSDOS
  428. X#undef    GEMDOS        /* This amusing garbage is to get all my */
  429. X#undef    DOS        /* define's past some compilers, which */
  430. X#undef    BSD        /* apparently define some of these themselves */
  431. X#undef    SYSV
  432. X#undef    UNIX
  433. X#undef    MTS
  434. X
  435. X#define    MSDOS    0        /* MSDOS machine */
  436. X#define    GEMDOS    0        /* Atari, GEMDOS */
  437. X#define    BSD    1        /* BSD4.2 or 4.3 */
  438. X#define    SYSV    0        /* Also uses BSD */
  439. X#define    MTS    0        /* MTS or 370(?) */
  440. X
  441. X/*
  442. X * Assumptions:
  443. X * char = 8 bits
  444. X * short = 16 bits
  445. X * long = 32 bits
  446. X * int >= 16 bits
  447. X */
  448. X
  449. X#if    MSDOS || GEMDOS
  450. X#define    DOS    1
  451. X#define    CUTOFF    '\\'
  452. X#endif
  453. X
  454. X#if    !MSDOS
  455. X#define    envfind    getenv
  456. X#define    setmem(a, b, c)    memset(a, c, b)
  457. X#endif
  458. X
  459. X#if    BSD || SYSV
  460. X#define    UNIX    1
  461. X#define    CUTOFF    '/'
  462. X#include <ctype.h>
  463. X#endif
  464. X
  465. X#if    MTS
  466. X#define rindex strrchr
  467. X#define index strchr
  468. X#undef  USEGFINFO        /* define this to use GFINFO for directory */
  469. X#define USECATSCAN        /* scanning, else use CATSCAN/FILEINFO... */
  470. X#define    CUTOFF    sepchr[0]
  471. X#endif
  472. X
  473. X/*  ARC - Archive utility - ARC Header
  474. X  
  475. X    Version 2.17, created on 04/22/87 at 13:09:43
  476. X  
  477. X(C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
  478. X  
  479. X    By:     Thom Henderson
  480. X  
  481. X    Description: 
  482. X     This is the header file for the ARC archive utility.  It defines
  483. X     global parameters and the references to the external data.
  484. X  
  485. X  
  486. X    Language:
  487. X     Computer Innovations Optimizing C86
  488. X*/
  489. X
  490. X#define ARCMARK 26        /* special archive marker        */
  491. X#define ARCVER 9        /* archive header version code   */
  492. X#define STRLEN 100        /* system standard string length */
  493. X#define FNLEN 13        /* file name length              */
  494. X#define MAXARG 25        /* maximum number of arguments   */
  495. X
  496. X#ifndef DONT_DEFINE        /* Defined by arcdata.c */
  497. X#include "arcs.h"
  498. X
  499. Xextern int      keepbak;    /* true if saving the old archive */
  500. X#if    !DOS
  501. Xextern int      image;        /* true to suppress CRLF/LF x-late */
  502. X#endif
  503. X#if    MTS
  504. Xextern char     sepchr[2];    /* Shared file separator, default = ':' */
  505. Xextern char     tmpchr[2];    /* Temporary file prefix, default = '-' */
  506. X#endif
  507. X#if    GEMDOS
  508. Xextern int      hold;        /* hold screen before exiting */
  509. X#endif
  510. Xextern int      warn;        /* true to print warnings */
  511. Xextern int      note;        /* true to print comments */
  512. Xextern int      bose;        /* true to be verbose */
  513. Xextern int      nocomp;        /* true to suppress compression */
  514. Xextern int      overlay;    /* true to overlay on extract */
  515. Xextern int      kludge;        /* kludge flag */
  516. Xextern char    *arctemp;    /* arc temp file prefix */
  517. Xextern char    *password;    /* encryption password pointer */
  518. Xextern int      nerrs;        /* number of errors encountered */
  519. Xextern int      changing;    /* true if archive being modified */
  520. X
  521. Xextern char     hdrver;        /* header version */
  522. X
  523. Xextern FILE    *arc;        /* the old archive */
  524. Xextern FILE    *new;        /* the new archive */
  525. Xextern char     arcname[STRLEN];/* storage for archive name */
  526. Xextern char     bakname[STRLEN];/* storage for backup copy name */
  527. Xextern char     newname[STRLEN];/* storage for new archive name */
  528. Xextern unsigned short arcdate;    /* archive date stamp */
  529. Xextern unsigned short arctime;    /* archive time stamp */
  530. Xextern unsigned short olddate;    /* old archive date stamp */
  531. Xextern unsigned short oldtime;    /* old archive time stamp */
  532. Xextern int      dosquash;    /* squash instead of crunch */
  533. X#endif                /* DONT_DEFINE */
  534. ________This_Is_The_END________
  535. if test `wc -c < arc.h` -ne     3318; then
  536.     echo 'shar: arc.h was damaged during transit (should have been     3318 bytes)'
  537. fi
  538. fi        ; : end of overwriting check
  539. echo 'x - arcadd.c'
  540. if test -f arcadd.c; then echo 'shar: not overwriting arcadd.c'; else
  541. sed 's/^X//' << '________This_Is_The_END________' > arcadd.c
  542. X/*
  543. X * $Header: arcadd.c,v 1.8 88/06/13 00:31:15 hyc Locked $
  544. X */
  545. X
  546. X/*
  547. X * ARC - Archive utility - ARCADD
  548. X * 
  549. X * Version 3.40, created on 06/18/86 at 13:10:18
  550. X * 
  551. X * (C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
  552. X * 
  553. X * By:  Thom Henderson
  554. X * 
  555. X * Description: This file contains the routines used to add files to an archive.
  556. X * 
  557. X * Language: Computer Innovations Optimizing C86
  558. X */
  559. X#include <stdio.h>
  560. X#include "arc.h"
  561. X#if    MTS
  562. X#include <mts.h>
  563. X#endif
  564. X
  565. Xstatic    void    addfile();
  566. Xchar    *strcpy();
  567. Xint    strcmp(), strlen(), free(), readhdr(), unlink();
  568. X#if    UNIX
  569. Xint    izadir();
  570. X#endif
  571. Xvoid    writehdr(), filecopy(), getstamp();
  572. Xvoid    pack(), closearc(), openarc(), abort();
  573. X
  574. Xvoid
  575. Xaddarc(num, arg, move, update, fresh)        /* add files to archive */
  576. X    int             num;    /* number of arguments */
  577. X    char           *arg[];    /* pointers to arguments */
  578. Xint             move;        /* true if moving file */
  579. Xint             update;        /* true if updating */
  580. Xint             fresh;        /* true if freshening */
  581. X{
  582. X    char           *d, *dir();    /* directory junk */
  583. X    char            buf[STRLEN];    /* pathname buffer */
  584. X    char          **path;    /* pointer to pointers to paths */
  585. X    char          **name;    /* pointer to pointers to names */
  586. X    int             nfiles = 0;    /* number of files in lists */
  587. X    int             notemp;    /* true until a template works */
  588. X    int             nowork = 1;    /* true until files are added */
  589. X    char           *i, *rindex();    /* string indexing junk */
  590. X    char           *malloc(), *realloc();    /* memory allocators */
  591. X    int             n;    /* index */
  592. X#if    MSDOS
  593. X    unsigned int    coreleft();    /* remaining memory reporter */
  594. X#endif
  595. X    int        addbunch();
  596. X
  597. X    if (num < 1) {        /* if no files named */
  598. X        num = 1;    /* then fake one */
  599. X#if    DOS
  600. X        arg[0] = "*.*";    /* add everything */
  601. X#endif
  602. X#if    UNIX
  603. X        arg[0] = "*";
  604. X#endif
  605. X#if    MTS
  606. X        arg[0] = "?";
  607. X#endif
  608. X    }
  609. X    path = (char **) malloc(sizeof(char **));
  610. X    name = (char **) malloc(sizeof(char **));
  611. X
  612. X
  613. X    for (n = 0; n < num; n++) {    /* for each template supplied */
  614. X        strcpy(buf, arg[n]);    /* get ready to fix path */
  615. X#if    !MTS
  616. X        if (!(i = rindex(buf, '\\')))
  617. X            if (!(i = rindex(buf, '/')))
  618. X                if (!(i = rindex(buf, ':')))
  619. X                    i = buf - 1;
  620. X#else
  621. X        if (!(i = rindex(buf, sepchr[0])))
  622. X            if (buf[0] != tmpchr[0])
  623. X                i = buf - 1;
  624. X            else
  625. X                i = buf;
  626. X#endif
  627. X        i++;        /* pointer to where name goes */
  628. X
  629. X        notemp = 1;    /* reset files flag */
  630. X        for (d = dir(arg[n]); d; d = dir(NULL)) {
  631. X            notemp = 0;    /* template is giving results */
  632. X            nfiles++;    /* add each matching file */
  633. X            path = (char **) realloc(path, nfiles * sizeof(char **));
  634. X            name = (char **) realloc(name, nfiles * sizeof(char **));
  635. X            strcpy(i, d);    /* put name in path */
  636. X            path[nfiles - 1] = malloc(strlen(buf) + 1);
  637. X            strcpy(path[nfiles - 1], buf);
  638. X            name[nfiles - 1] = d;    /* save name */
  639. X#if    MSDOS
  640. X            if (coreleft() < 5120) {
  641. X                nfiles = addbunch(nfiles, path, name, move, update, fresh);
  642. X                nowork = nowork && !nfiles;
  643. X                while (nfiles) {
  644. X                    free(path[--nfiles]);
  645. X                    free(name[nfiles]);
  646. X                }
  647. X                free(path);
  648. X                free(name);
  649. X                path = name = NULL;
  650. X            }
  651. X#endif
  652. X        }
  653. X        if (notemp && warn)
  654. X            printf("No files match: %s\n", arg[n]);
  655. X    }
  656. X
  657. X    if (nfiles) {
  658. X        nfiles = addbunch(nfiles, path, name, move, update, fresh);
  659. X        nowork = nowork && !nfiles;
  660. X        while (nfiles) {
  661. X            free(path[--nfiles]);
  662. X            free(name[nfiles]);
  663. X        }
  664. X        free(path);
  665. X        free(name);
  666. X    }
  667. X    if (nowork && warn)
  668. X        printf("No files were added.\n");
  669. X}
  670. X
  671. Xint
  672. Xaddbunch(nfiles, path, name, move, update, fresh)    /* add a bunch of files */
  673. X    int             nfiles;    /* number of files to add */
  674. X    char          **path;    /* pointers to pathnames */
  675. X    char          **name;    /* pointers to filenames */
  676. X    int             move;    /* true if moving file */
  677. X    int             update;    /* true if updating */
  678. X    int             fresh;    /* true if freshening */
  679. X{
  680. X    int             m, n;    /* indices */
  681. X    char           *d;    /* swap pointer */
  682. X    struct heads    hdr;    /* file header data storage */
  683. X
  684. X    for (n = 0; n < nfiles - 1; n++) {    /* sort the list of names */
  685. X        for (m = n + 1; m < nfiles; m++) {
  686. X            if (strcmp(name[n], name[m]) > 0) {
  687. X                d = path[n];
  688. X                path[n] = path[m];
  689. X                path[m] = d;
  690. X                d = name[n];
  691. X                name[n] = name[m];
  692. X                name[m] = d;
  693. X            }
  694. X        }
  695. X    }
  696. X
  697. X    for (n = 0; n < nfiles - 1;) {    /* consolidate the list of names */
  698. X        if (!strcmp(path[n], path[n + 1])    /* if duplicate names */
  699. X            ||!strcmp(path[n], arcname)    /* or this archive */
  700. X#if    UNIX
  701. X            ||izadir(path[n])    /* or a directory */
  702. X#endif
  703. X            ||!strcmp(path[n], newname)    /* or the new version */
  704. X            ||!strcmp(path[n], bakname)) {    /* or its backup */
  705. X            free(path[n]);    /* then forget the file */
  706. X            free(name[n]);
  707. X            for (m = n; m < nfiles - 1; m++) {
  708. X                path[m] = path[m + 1];
  709. X                name[m] = name[m + 1];
  710. X            }
  711. X            nfiles--;
  712. X        } else
  713. X            n++;    /* else test the next one */
  714. X    }
  715. X
  716. X    if (!strcmp(path[n], arcname)    /* special check for last file */
  717. X        ||!strcmp(path[n], newname)    /* courtesy of Rick Moore */
  718. X#if    UNIX
  719. X        ||izadir(path[n])
  720. X#endif
  721. X        || !strcmp(path[n], bakname)) {
  722. X        free(path[n]);
  723. X        free(name[n]);
  724. X        nfiles--;
  725. X    }
  726. X    if (!nfiles)        /* make sure we got some */
  727. X        return 0;
  728. X
  729. X    for (n = 0; n < nfiles - 1; n++) {    /* watch out for duplicate
  730. X                         * names */
  731. X        if (!strcmp(name[n], name[n + 1]))
  732. X            abort("Duplicate filenames:\n  %s\n  %s", path[n], path[n + 1]);
  733. X    }
  734. X    openarc(1);        /* open archive for changes */
  735. X
  736. X    for (n = 0; n < nfiles; n++)    /* add each file in the list */
  737. X        addfile(path[n], name[n], update, fresh);
  738. X
  739. X    /* now we must copy over all files that follow our additions */
  740. X
  741. X    while (readhdr(&hdr, arc)) {    /* while more entries to copy */
  742. X        writehdr(&hdr, new);
  743. X        filecopy(arc, new, hdr.size);
  744. X    }
  745. X    hdrver = 0;        /* archive EOF type */
  746. X    writehdr(&hdr, new);    /* write out our end marker */
  747. X    closearc(1);        /* close archive after changes */
  748. X
  749. X    if (move) {        /* if this was a move */
  750. X        for (n = 0; n < nfiles; n++) {    /* then delete each file
  751. X                         * added */
  752. X            if (unlink(path[n]) && warn) {
  753. X                printf("Cannot unsave %s\n", path[n]);
  754. X                nerrs++;
  755. X            }
  756. X        }
  757. X    }
  758. X    return nfiles;        /* say how many were added */
  759. X}
  760. X
  761. Xstatic          void
  762. Xaddfile(path, name, update, fresh)    /* add named file to archive */
  763. X    char           *path;    /* path name of file to add */
  764. X    char           *name;    /* name of file to add */
  765. X    int             update;    /* true if updating */
  766. X    int             fresh;    /* true if freshening */
  767. X{
  768. X    struct heads    nhdr;    /* data regarding the new file */
  769. X    struct heads    ohdr;    /* data regarding an old file */
  770. X    FILE           *f, *fopen();    /* file to add, opener */
  771. X    long            starts, ftell();    /* file locations */
  772. X    int             upd = 0;/* true if replacing an entry */
  773. X
  774. X#if    !MTS
  775. X    if (!(f = fopen(path, "rb")))
  776. X#else
  777. X    if (image)
  778. X        f = fopen(path, "rb");
  779. X    else
  780. X        f = fopen(path, "r");
  781. X    if (!f)
  782. X#endif
  783. X    {
  784. X        if (warn) {
  785. X            printf("Cannot read file: %s\n", path);
  786. X            nerrs++;
  787. X        }
  788. X        return;
  789. X    }
  790. X    strcpy(nhdr.name, name);/* save name */
  791. X    nhdr.size = 0;        /* clear out size storage */
  792. X    nhdr.crc = 0;        /* clear out CRC check storage */
  793. X#if    !MTS
  794. X    getstamp(f, &nhdr.date, &nhdr.time);
  795. X#else
  796. X    {
  797. X    char *buffer, *malloc();
  798. X    int    inlen;
  799. X    struct    GDDSECT    *region;
  800. X
  801. X    region=gdinfo(f->_fd);
  802. X    inlen=region->GDINLEN;
  803. X    buffer=malloc(inlen);   /* maximum line length */
  804. X    setbuf(f,buffer);        
  805. X    f->_bufsiz=inlen;        
  806. X    f->_mods|=0x00040000;   /* Don't do "$continue with" */
  807. X    f->_mods&=0xfff7ffff;   /* turn it off, if set... */
  808. X    }
  809. X    getstamp(path, &nhdr.date, &nhdr.time);
  810. X#endif
  811. X
  812. X    /* position archive to spot for new file */
  813. X
  814. X    if (arc) {        /* if adding to existing archive */
  815. X        starts = ftell(arc);    /* where are we? */
  816. X        while (readhdr(&ohdr, arc)) {    /* while more files to check */
  817. X            if (!strcmp(ohdr.name, nhdr.name)) {
  818. X                upd = 1;    /* replace existing entry */
  819. X                if (update || fresh) {    /* if updating or
  820. X                             * freshening */
  821. X                    if (nhdr.date < ohdr.date
  822. X                        || (nhdr.date == ohdr.date && nhdr.time <= ohdr.time)) {
  823. X                        fseek(arc, starts, 0);
  824. X                        fclose(f);
  825. X                        return;    /* skip if not newer */
  826. X                    }
  827. X                }
  828. X            }
  829. X            if (strcmp(ohdr.name, nhdr.name) >= 0)
  830. X                break;    /* found our spot */
  831. X
  832. X            writehdr(&ohdr, new);    /* entry preceeds update;
  833. X                         * keep it */
  834. X            filecopy(arc, new, ohdr.size);
  835. X            starts = ftell(arc);    /* now where are we? */
  836. X        }
  837. X
  838. X        if (upd) {    /* if an update */
  839. X            if (note) {
  840. X                printf("Updating file: %-12s  ", name);
  841. X                fflush(stdout);
  842. X            }
  843. X            fseek(arc, ohdr.size, 1);
  844. X        } else if (fresh) {    /* else if freshening */
  845. X            fseek(arc, starts, 0);    /* then do not add files */
  846. X            fclose(f);
  847. X            return;
  848. X        } else {    /* else adding a new file */
  849. X            if (note) {
  850. X                printf("Adding file:   %-12s  ", name);
  851. X                fflush(stdout);
  852. X            }
  853. X            fseek(arc, starts, 0);    /* reset for next time */
  854. X        }
  855. X    } else {        /* no existing archive */
  856. X        if (fresh) {    /* cannot freshen nothing */
  857. X            fclose(f);
  858. X            return;
  859. X        } else if (note) {    /* else adding a file */
  860. X            printf("Adding file:   %-12s  ", name);
  861. X            fflush(stdout);
  862. X        }
  863. X    }
  864. X
  865. X    starts = ftell(new);    /* note where header goes */
  866. X    hdrver = ARCVER;        /* anything but end marker */
  867. X    writehdr(&nhdr, new);    /* write out header skeleton */
  868. X    pack(f, new, &nhdr);    /* pack file into archive */
  869. X    strcpy(nhdr.name, name);
  870. X    fseek(new, starts, 0);    /* move back to header skeleton */
  871. X    writehdr(&nhdr, new);    /* write out real header */
  872. X    fseek(new, nhdr.size, 1);    /* skip over data to next header */
  873. X    fclose(f);        /* all done with the file */
  874. X}
  875. ________This_Is_The_END________
  876. if test `wc -c < arcadd.c` -ne     9286; then
  877.     echo 'shar: arcadd.c was damaged during transit (should have been     9286 bytes)'
  878. fi
  879. fi        ; : end of overwriting check
  880. echo 'x - arccode.c'
  881. if test -f arccode.c; then echo 'shar: not overwriting arccode.c'; else
  882. sed 's/^X//' << '________This_Is_The_END________' > arccode.c
  883. X/*
  884. X * $Header: arccode.c,v 1.1 88/06/01 15:15:58 hyc Locked $
  885. X */
  886. X
  887. X/*
  888. X * ARC - Archive utility - ARCCODE
  889. X * 
  890. X * Version 1.02, created on 01/20/86 at 13:33:35
  891. X * 
  892. X * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  893. X * 
  894. X * By:  Thom Henderson
  895. X * 
  896. X * Description: This file contains the routines used to encrypt and decrypt data
  897. X * in an archive.  The encryption method is nothing fancy, being just a
  898. X * routine XOR, but it is used on the packed data, and uses a variable length
  899. X * key.  The end result is something that is in theory crackable, but I'd
  900. X * hate to try it.  It should be more than sufficient for casual use.
  901. X * 
  902. X * Language: Computer Innovations Optimizing C86
  903. X */
  904. X#include <stdio.h>
  905. X#include "arc.h"
  906. X
  907. Xstatic char    *p;        /* password pointer */
  908. X
  909. Xvoid
  910. Xsetcode()
  911. X{                /* get set for encoding/decoding */
  912. X    p = password;        /* reset password pointer */
  913. X}
  914. X
  915. Xunsigned char
  916. Xcode(c)                /* encode some character */
  917. X    char            c;    /* character to encode */
  918. X{
  919. X    if (p) {        /* if password is in use */
  920. X        if (!*p)    /* if we reached the end */
  921. X            p = password;    /* then wrap back to the start */
  922. X        return c ^ *p++;/* very simple here */
  923. X    } else
  924. X        return c;    /* else no encryption */
  925. X}
  926. ________This_Is_The_END________
  927. if test `wc -c < arccode.c` -ne     1204; then
  928.     echo 'shar: arccode.c was damaged during transit (should have been     1204 bytes)'
  929. fi
  930. fi        ; : end of overwriting check
  931. echo 'x - arccvt.c'
  932. if test -f arccvt.c; then echo 'shar: not overwriting arccvt.c'; else
  933. sed 's/^X//' << '________This_Is_The_END________' > arccvt.c
  934. X/*
  935. X * $Header: arccvt.c,v 1.5 88/06/01 19:17:40 hyc Locked $
  936. X */
  937. X
  938. X/*
  939. X * ARC - Archive utility - ARCCVT
  940. X * 
  941. X * Version 1.16, created on 02/03/86 at 22:53:02
  942. X * 
  943. X * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  944. X * 
  945. X * By:  Thom Henderson
  946. X * 
  947. X * Description: This file contains the routines used to convert archives to use
  948. X * newer file storage methods.
  949. X * 
  950. X * Language: Computer Innovations Optimizing C86
  951. X */
  952. X#include <stdio.h>
  953. X#include "arc.h"
  954. X
  955. Xvoid    openarc(), rempath(), closearc(), abort(), pack(), writehdr(), filecopy();
  956. Xint    match(), readhdr(), unpack(), unlink();
  957. X
  958. Xstatic char     tempname[STRLEN];    /* temp file name */
  959. X
  960. Xvoid
  961. Xcvtarc(num, arg)        /* convert archive */
  962. X    int             num;    /* number of arguments */
  963. X    char           *arg[];    /* pointers to arguments */
  964. X{
  965. X    struct heads    hdr;    /* file header */
  966. X    int             cvt;    /* true to convert current file */
  967. X    int             did[MAXARG];/* true when argument was used */
  968. X    int             n;    /* index */
  969. X    char           *makefnam();    /* filename fixer */
  970. X    FILE           *fopen();/* file opener */
  971. X    void            cvtfile();
  972. X
  973. X    if (arctemp)        /* use temp area if specified */
  974. X        sprintf(tempname, "%s.CVT", arctemp);
  975. X    else
  976. X        makefnam("$ARCTEMP.CVT", arcname, tempname);
  977. X#if    !DOS
  978. X    image = 1;
  979. X#endif
  980. X
  981. X    openarc(1);        /* open archive for changes */
  982. X
  983. X    for (n = 0; n < num; n++)    /* for each argument */
  984. X        did[n] = 0;    /* reset usage flag */
  985. X    rempath(num, arg);    /* strip off paths */
  986. X
  987. X    if (num) {        /* if files were named */
  988. X        while (readhdr(&hdr, arc)) {    /* while more files to check */
  989. X            cvt = 0;/* reset convert flag */
  990. X            for (n = 0; n < num; n++) {    /* for each template
  991. X                             * given */
  992. X                if (match(hdr.name, arg[n])) {
  993. X                    cvt = 1;    /* turn on convert flag */
  994. X                    did[n] = 1;    /* turn on usage flag */
  995. X                    break;    /* stop looking */
  996. X                }
  997. X            }
  998. X
  999. X            if (cvt)/* if converting this one */
  1000. X                cvtfile(&hdr);    /* then do it */
  1001. X            else {    /* else just copy it */
  1002. X                writehdr(&hdr, new);
  1003. X                filecopy(arc, new, hdr.size);
  1004. X            }
  1005. X        }
  1006. X    } else
  1007. X        while (readhdr(&hdr, arc))    /* else convert all files */
  1008. X            cvtfile(&hdr);
  1009. X
  1010. X    hdrver = 0;        /* archive EOF type */
  1011. X    writehdr(&hdr, new);    /* write out our end marker */
  1012. X    closearc(1);        /* close archive after changes */
  1013. X
  1014. X    if (note) {
  1015. X        for (n = 0; n < num; n++) {    /* report unused args */
  1016. X            if (!did[n]) {
  1017. X                printf("File not found: %s\n", arg[n]);
  1018. X                nerrs++;
  1019. X            }
  1020. X        }
  1021. X    }
  1022. X}
  1023. X
  1024. Xvoid
  1025. Xcvtfile(hdr)            /* convert a file */
  1026. X    struct heads   *hdr;    /* pointer to header data */
  1027. X{
  1028. X    long            starts, ftell();    /* where the file goes */
  1029. X    FILE           *tmp, *fopen();    /* temporary file */
  1030. X
  1031. X    if (!(tmp = fopen(tempname, "w+b")))
  1032. X        abort("Unable to create temporary file %s", tempname);
  1033. X
  1034. X    if (note) {
  1035. X        printf("Converting file: %-12s   reading, ", hdr->name);
  1036. X        fflush(stdout);
  1037. X    }
  1038. X    unpack(arc, tmp, hdr);    /* unpack the entry */
  1039. X    fseek(tmp, 0L, 0);    /* reset temp for reading */
  1040. X
  1041. X    starts = ftell(new);    /* note where header goes */
  1042. X    hdrver = ARCVER;        /* anything but end marker */
  1043. X    writehdr(hdr, new);    /* write out header skeleton */
  1044. X    pack(tmp, new, hdr);    /* pack file into archive */
  1045. X    fseek(new, starts, 0);    /* move back to header skeleton */
  1046. X    writehdr(hdr, new);    /* write out real header */
  1047. X    fseek(new, hdr->size, 1);    /* skip over data to next header */
  1048. X    fclose(tmp);        /* all done with the file */
  1049. X    if (unlink(tempname) && warn) {
  1050. X        printf("Cannot unsave %s\n", tempname);
  1051. X        nerrs++;
  1052. X    }
  1053. X}
  1054. ________This_Is_The_END________
  1055. if test `wc -c < arccvt.c` -ne     3396; then
  1056.     echo 'shar: arccvt.c was damaged during transit (should have been     3396 bytes)'
  1057. fi
  1058. fi        ; : end of overwriting check
  1059. echo 'x - arcdata.c'
  1060. if test -f arcdata.c; then echo 'shar: not overwriting arcdata.c'; else
  1061. sed 's/^X//' << '________This_Is_The_END________' > arcdata.c
  1062. X/*
  1063. X * $Header: arcdata.c,v 1.6 88/06/01 19:17:58 hyc Locked $
  1064. X */
  1065. X
  1066. X/*  ARC - Archive utility - ARCDATA
  1067. X
  1068. X    Version 2.17, created on 04/22/87 at 13:09:43
  1069. X
  1070. X(C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
  1071. X
  1072. X    By:     Thom Henderson
  1073. X
  1074. X    Description: 
  1075. X     This file defines the external data storage used by the ARC
  1076. X     archive utility.
  1077. X
  1078. X
  1079. X    Language:
  1080. X     Computer Innovations Optimizing C86
  1081. X*/
  1082. X#include <stdio.h>
  1083. X
  1084. X#define DONT_DEFINE
  1085. X#include "arc.h"
  1086. X
  1087. Xint             keepbak = 0;    /* true if saving the old archive */
  1088. X#if    UNIX
  1089. Xint        image = 1;    /* true to suppress CRLF/LF x-late */
  1090. X#endif
  1091. X#if    MTS
  1092. Xint             image = 0;    /* true to suppress EBCDIC/ASCII x-late */
  1093. Xchar            sepchr[2] = ":";/* Shared file separator */
  1094. Xchar            tmpchr[2] = "-";/* Temporary file prefix */
  1095. X#endif
  1096. X#if    GEMDOS
  1097. Xint        hold = 0;    /* true to pause before exit */
  1098. X#endif
  1099. Xint             warn = 1;    /* true to print warnings */
  1100. Xint             note = 1;    /* true to print comments */
  1101. Xint             bose = 0;    /* true to be verbose */
  1102. Xint             nocomp = 0;    /* true to suppress compression */
  1103. Xint             overlay = 0;    /* true to overlay on extract */
  1104. Xint             kludge = 0;    /* kludge flag */
  1105. Xchar           *arctemp = NULL;    /* arc temp file prefix */
  1106. Xchar           *password = NULL;/* encryption password pointer */
  1107. Xint             nerrs = 0;    /* number of errors encountered */
  1108. Xint        changing = 0;    /* true if archive being modified */
  1109. X
  1110. Xchar            hdrver;        /* header version */
  1111. X
  1112. XFILE           *arc;        /* the old archive */
  1113. XFILE           *new;        /* the new archive */
  1114. Xchar            arcname[STRLEN];    /* storage for archive name */
  1115. Xchar            bakname[STRLEN];    /* storage for backup copy name */
  1116. Xchar            newname[STRLEN];    /* storage for new archive name */
  1117. Xunsigned short  arcdate = 0;    /* archive date stamp */
  1118. Xunsigned short  arctime = 0;    /* archive time stamp */
  1119. Xunsigned short  olddate = 0;    /* old archive date stamp */
  1120. Xunsigned short  oldtime = 0;    /* old archive time stamp */
  1121. Xint        dosquash = 0;    /* true to squash instead of crunch */
  1122. ________This_Is_The_END________
  1123. if test `wc -c < arcdata.c` -ne     2070; then
  1124.     echo 'shar: arcdata.c was damaged during transit (should have been     2070 bytes)'
  1125. fi
  1126. fi        ; : end of overwriting check
  1127. echo 'x - arcdel.c'
  1128. if test -f arcdel.c; then echo 'shar: not overwriting arcdel.c'; else
  1129. sed 's/^X//' << '________This_Is_The_END________' > arcdel.c
  1130. X/*
  1131. X * $Header: arcdel.c,v 1.3 88/04/19 01:39:32 hyc Exp $
  1132. X */
  1133. X
  1134. X/*
  1135. X * ARC - Archive utility - ARCDEL
  1136. X * 
  1137. X * Version 2.09, created on 02/03/86 at 22:53:27
  1138. X * 
  1139. X * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  1140. X * 
  1141. X * By:  Thom Henderson
  1142. X * 
  1143. X * Description: This file contains the routines used to delete entries in an
  1144. X * archive.
  1145. X * 
  1146. X * Language: Computer Innovations Optimizing C86
  1147. X */
  1148. X#include <stdio.h>
  1149. X#include "arc.h"
  1150. X
  1151. Xvoid    abort(), rempath(), openarc(), closearc(), writehdr(), filecopy();
  1152. Xint    match(), readhdr();
  1153. X
  1154. Xvoid
  1155. Xdelarc(num, arg)        /* remove files from archive */
  1156. X    int             num;    /* number of arguments */
  1157. X    char           *arg[];    /* pointers to arguments */
  1158. X{
  1159. X    struct heads    hdr;    /* header data */
  1160. X    int             del;    /* true to delete a file */
  1161. X    int             did[MAXARG];/* true when argument used */
  1162. X    int             n;    /* index */
  1163. X
  1164. X    if (!num)        /* she must specify which */
  1165. X        abort("You must tell me which files to delete!");
  1166. X
  1167. X    for (n = 0; n < num; n++)    /* for each argument */
  1168. X        did[n] = 0;    /* reset usage flag */
  1169. X    rempath(num, arg);    /* strip off paths */
  1170. X
  1171. X    openarc(1);        /* open archive for changes */
  1172. X
  1173. X    while (readhdr(&hdr, arc)) {    /* while more entries in archive */
  1174. X        del = 0;    /* reset delete flag */
  1175. X        for (n = 0; n < num; n++) {    /* for each template given */
  1176. X            if (match(hdr.name, arg[n])) {
  1177. X                del = 1;    /* turn on delete flag */
  1178. X                did[n] = 1;    /* turn on usage flag */
  1179. X                break;    /* stop looking */
  1180. X            }
  1181. X        }
  1182. X
  1183. X        if (del) {    /* skip over unwanted files */
  1184. X            fseek(arc, hdr.size, 1);
  1185. X            if (note)
  1186. X                printf("Deleting file: %s\n", hdr.name);
  1187. X        } else {    /* else copy over file data */
  1188. X            writehdr(&hdr, new);    /* write out header and file */
  1189. X            filecopy(arc, new, hdr.size);
  1190. X        }
  1191. X    }
  1192. X
  1193. X    hdrver = 0;        /* special end of archive type */
  1194. X    writehdr(&hdr, new);    /* write out archive end marker */
  1195. X    closearc(1);        /* close archive after changes */
  1196. X
  1197. X    if (note) {
  1198. X        for (n = 0; n < num; n++) {    /* report unused arguments */
  1199. X            if (!did[n]) {
  1200. X                printf("File not found: %s\n", arg[n]);
  1201. X                nerrs++;
  1202. X            }
  1203. X        }
  1204. X    }
  1205. X}
  1206. ________This_Is_The_END________
  1207. if test `wc -c < arcdel.c` -ne     2055; then
  1208.     echo 'shar: arcdel.c was damaged during transit (should have been     2055 bytes)'
  1209. fi
  1210. fi        ; : end of overwriting check
  1211. echo 'x - arcdos.c'
  1212. if test -f arcdos.c; then echo 'shar: not overwriting arcdos.c'; else
  1213. sed 's/^X//' << '________This_Is_The_END________' > arcdos.c
  1214. X/*
  1215. X * $Header: arcdos.c,v 1.5 88/06/13 00:40:49 hyc Locked $
  1216. X */
  1217. X
  1218. X/*
  1219. X * ARC - Archive utility - ARCDOS
  1220. X * 
  1221. X * Version 1.44, created on 07/25/86 at 14:17:38
  1222. X * 
  1223. X * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  1224. X * 
  1225. X * By:  Thom Henderson
  1226. X * 
  1227. X * Description: This file contains certain DOS level routines that assist in
  1228. X * doing fancy things with an archive, primarily reading and setting the date
  1229. X * and time last modified.
  1230. X * 
  1231. X * These are, by nature, system dependant functions.  But they are also, by
  1232. X * nature, very expendable.
  1233. X * 
  1234. X * Language: Computer Innovations Optimizing C86
  1235. X */
  1236. X#include <stdio.h>
  1237. X#include "arc.h"
  1238. X
  1239. X#if    MSDOS
  1240. X#include "fileio2.h"        /* needed for filehand */
  1241. X#endif
  1242. X
  1243. X#if    UNIX
  1244. X#include <sys/types.h>
  1245. X#include <sys/stat.h>
  1246. X#include <sys/time.h>
  1247. X#include "tws.h"
  1248. X#endif
  1249. X
  1250. X#if    SYSV
  1251. Xstruct timeval {
  1252. X    long tv_sec;
  1253. X    long tv_usec;
  1254. X};
  1255. X#endif
  1256. X
  1257. X#if    GEMDOS
  1258. X#include <osbind.h>
  1259. X#endif
  1260. X
  1261. Xchar    *strcpy(), *strcat(), *malloc();
  1262. X
  1263. Xvoid
  1264. Xgetstamp(f, date, time)        /* get a file's date/time stamp */
  1265. X#if    !MTS
  1266. X    FILE           *f;    /* file to get stamp from */
  1267. X#else
  1268. X    char           *f;    /* filename "" "" */
  1269. X#endif
  1270. X    unsigned short   *date, *time;    /* storage for the stamp */
  1271. X{
  1272. X#if    MSDOS
  1273. X    struct {
  1274. X        int             ax, bx, cx, dx, si, di, ds, es;
  1275. X    }               reg;
  1276. X
  1277. X    reg.ax = 0x5700;    /* get date/time */
  1278. X    reg.bx = filehand(f);    /* file handle */
  1279. X    if (sysint21(®, ®) & 1)    /* DOS call */
  1280. X        printf("Get timestamp fail (%d)\n", reg.ax);
  1281. X
  1282. X    *date = reg.dx;        /* save date/time */
  1283. X    *time = reg.cx;
  1284. X#endif
  1285. X#if    GEMDOS
  1286. X    int    fd, ret[2];
  1287. X
  1288. X    fd = fileno(f);
  1289. X    Fdatime(ret, fd, 0);
  1290. X    *date = ret[1];
  1291. X    *time = ret[0];
  1292. X#endif
  1293. X#if    UNIX
  1294. X    char           *ctime();
  1295. X    struct stat    *buf;
  1296. X    int             day, hr, min, sec, yr, imon;
  1297. X    static char     mon[4], *mons[12] = {
  1298. X                   "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  1299. X                    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  1300. X    };
  1301. X
  1302. X    buf = (struct stat *) malloc(sizeof(struct stat));
  1303. X    fstat(fileno(f), buf);
  1304. X
  1305. X    sscanf(ctime(&(buf->st_mtime)), "%*4s%3s%d%d:%d:%d%d", mon, &day, &hr, &min,
  1306. X           &sec, &yr);
  1307. X    for (imon = 0; imon < 12 && strcmp(mon, mons[imon]); imon++);
  1308. X
  1309. X    *date = (unsigned short) (((yr - 1980) << 9) + ((imon + 1) << 5) + day);
  1310. X    *time = (unsigned short) ((hr << 11) + (min << 5) + sec / 2);
  1311. X#endif
  1312. X#if    MTS
  1313. X    fortran         timein(),
  1314. X#if    USEGFINFO
  1315. X                    gfinfo();
  1316. X#else
  1317. X                    fileinfo();
  1318. X#endif
  1319. X    int             stclk[2];
  1320. X    char            name[24];
  1321. X    struct bigtime {
  1322. X        int             greg;
  1323. X        int             year;
  1324. X        int             mon;
  1325. X        int             day;
  1326. X        int             hour;
  1327. X        int             min;
  1328. X        int             sec;
  1329. X        int             usec;
  1330. X        int             week;
  1331. X        int             toff;
  1332. X        int             tzn1;
  1333. X        int             tzn2;
  1334. X    }               tvec;
  1335. X#if    USEGFINFO
  1336. X    static int      gfflag = 0x0009, gfdummy[2] = {
  1337. X                               0, 0
  1338. X    };
  1339. X    int             gfcinfo[18];
  1340. X#else
  1341. X    static int      cattype = 2;
  1342. X#endif
  1343. X
  1344. X    strcpy(name, f);
  1345. X    strcat(name, " ");
  1346. X#if    USEGFINFO
  1347. X    gfcinfo[0] = 18;
  1348. X    gfinfo(name, name, &gfflag, gfcinfo, gfdummy, gfdummy);
  1349. X    timein("*IBM MICROSECONDS*", &gfcinfo[16], &tvec);
  1350. X#else
  1351. X    fileinfo(name, &cattype, "CILCCT  ", stclk);
  1352. X    timein("*IBM MICROSECONDS*", stclk, &tvec);
  1353. X#endif
  1354. X
  1355. X    *date = (unsigned short) (((tvec.year - 1980) << 9) + ((tvec.mon) << 5) + tvec.day);
  1356. X    *time = (unsigned short) ((tvec.hour << 11) + (tvec.min << 5) + tvec.sec / 2);
  1357. X#endif
  1358. X}
  1359. X
  1360. Xvoid
  1361. Xsetstamp(f, date, time)        /* set a file's date/time stamp */
  1362. X    char           *f;    /* filename to stamp */
  1363. X    unsigned short    date, time;    /* desired date, time */
  1364. X{
  1365. X#if    MSDOS
  1366. X    FILE    *ff;
  1367. X    struct {
  1368. X        int             ax, bx, cx, dx, si, di, ds, es;
  1369. X    }               reg;
  1370. X
  1371. X    ff = fopen(f, "w+");    /* How else can I get a handle? */
  1372. X
  1373. X    reg.ax = 0x5701;    /* set date/time */
  1374. X    reg.bx = filehand(f);    /* file handle */
  1375. X    reg.cx = time;        /* desired time */
  1376. X    reg.dx = date;        /* desired date */
  1377. X    if (sysint21(®, ®) & 1)    /* DOS call */
  1378. X        printf("Set timestamp fail (%d)\n", reg.ax);
  1379. X    fclose(ff);
  1380. X#endif
  1381. X#if    GEMDOS
  1382. X    int    fd, set[2];
  1383. X
  1384. X    fd = Fopen(f, 0);
  1385. X    set[0] = time;
  1386. X    set[1] = date;
  1387. X    Fdatime(set, fd, 1);
  1388. X    Fclose(fd);
  1389. X#endif
  1390. X#if    UNIX
  1391. X    struct tws      tms;
  1392. X    struct timeval  tvp[2];
  1393. X    int    utimes();
  1394. X    twscopy(&tms, dtwstime());
  1395. X    tms.tw_sec = (time & 31) * 2;
  1396. X    tms.tw_min = (time >> 5) & 63;
  1397. X    tms.tw_hour = (time >> 11);
  1398. X    tms.tw_mday = date & 31;
  1399. X    tms.tw_mon = ((date >> 5) & 15) - 1;
  1400. X    tms.tw_year = (date >> 9) + 80;
  1401. X    tms.tw_clock = 0L;
  1402. X    tms.tw_flags = TW_NULL;
  1403. X    tvp[0].tv_sec = twclock(&tms);
  1404. X    tvp[1].tv_sec = tvp[0].tv_sec;
  1405. X    tvp[0].tv_usec = tvp[1].tv_usec = 0;
  1406. X    utimes(f, tvp);
  1407. X#endif
  1408. X}
  1409. X
  1410. X#if    MSDOS
  1411. Xint
  1412. Xfilehand(stream)        /* find handle on a file */
  1413. X    struct bufstr  *stream;    /* file to grab onto */
  1414. X{
  1415. X    return stream->bufhand;    /* return DOS 2.0 file handle */
  1416. X}
  1417. X#endif
  1418. X
  1419. X#if    UNIX
  1420. Xint
  1421. Xizadir(filename)        /* Is filename a directory? */
  1422. X    char           *filename;
  1423. X{
  1424. X    struct stat     buf;
  1425. X
  1426. X    if (stat(filename, &buf) != 0)
  1427. X        return (0);    /* Ignore if stat fails since */
  1428. X    else
  1429. X        return (buf.st_mode & S_IFDIR);    /* bad files trapped later */
  1430. X}
  1431. X#endif
  1432. ________This_Is_The_END________
  1433. if test `wc -c < arcdos.c` -ne     5008; then
  1434.     echo 'shar: arcdos.c was damaged during transit (should have been     5008 bytes)'
  1435. fi
  1436. fi        ; : end of overwriting check
  1437. echo 'x - arcext.c'
  1438. if test -f arcext.c; then echo 'shar: not overwriting arcext.c'; else
  1439. sed 's/^X//' << '________This_Is_The_END________' > arcext.c
  1440. X/*
  1441. X * $Header: arcext.c,v 1.5 88/06/01 19:26:31 hyc Locked $
  1442. X */
  1443. X
  1444. X/*
  1445. X * ARC - Archive utility - ARCEXT
  1446. X * 
  1447. X * Version 2.19, created on 10/24/86 at 14:53:32
  1448. X * 
  1449. X * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  1450. X * 
  1451. X * By:  Thom Henderson
  1452. X * 
  1453. X * Description: This file contains the routines used to extract files from an
  1454. X * archive.
  1455. X * 
  1456. X * Language: Computer Innovations Optimizing C86
  1457. X */
  1458. X#include <stdio.h>
  1459. X#include "arc.h"
  1460. X#if    !MSDOS
  1461. X#include <ctype.h>
  1462. X#endif
  1463. X
  1464. Xvoid    openarc(), closearc(), setstamp();
  1465. Xint    free(), match(), readhdr(), unpack();
  1466. Xchar    *strcpy(), *strcat();
  1467. X
  1468. Xvoid
  1469. Xextarc(num, arg, prt)        /* extract files from archive */
  1470. X    int             num;    /* number of arguments */
  1471. X    char           *arg[];    /* pointers to arguments */
  1472. X    int             prt;        /* true if printing */
  1473. X{
  1474. X    struct heads    hdr;    /* file header */
  1475. X    int             save;    /* true to save current file */
  1476. X    int             did[MAXARG];/* true when argument was used */
  1477. X    char           *i, *rindex();    /* string index */
  1478. X    char          **name, *malloc();    /* name pointer list,
  1479. X                         * allocator */
  1480. X    int             n;    /* index */
  1481. X    void            extfile();
  1482. X
  1483. X    name = (char **) malloc(num * sizeof(char *));    /* get storage for name
  1484. X                             * pointers */
  1485. X
  1486. X    for (n = 0; n < num; n++) {    /* for each argument */
  1487. X        did[n] = 0;    /* reset usage flag */
  1488. X#if    !MTS
  1489. X        if (!(i = rindex(arg[n], '\\')))    /* find start of name */
  1490. X            if (!(i = rindex(arg[n], '/')))
  1491. X                if (!(i = rindex(arg[n], ':')))
  1492. X                    i = arg[n] - 1;
  1493. X#else
  1494. X        if (!(i = rindex(arg[n], sepchr[0])))
  1495. X            if (arg[n][0] != tmpchr[0])
  1496. X                i = arg[n] - 1;
  1497. X            else
  1498. X                i = arg[n];
  1499. X#endif
  1500. X        name[n] = i + 1;
  1501. X    }
  1502. X
  1503. X
  1504. X    openarc(0);        /* open archive for reading */
  1505. X
  1506. X    if (num) {        /* if files were named */
  1507. X        while (readhdr(&hdr, arc)) {    /* while more files to check */
  1508. X            save = 0;    /* reset save flag */
  1509. X            for (n = 0; n < num; n++) {    /* for each template
  1510. X                             * given */
  1511. X                if (match(hdr.name, name[n])) {
  1512. X                    save = 1;    /* turn on save flag */
  1513. X                    did[n] = 1;    /* turn on usage flag */
  1514. X                    break;    /* stop looking */
  1515. X                }
  1516. X            }
  1517. X
  1518. X            if (save)    /* extract if desired, else skip */
  1519. X                extfile(&hdr, arg[n], prt);
  1520. X            else
  1521. X                fseek(arc, hdr.size, 1);
  1522. X        }
  1523. X    } else
  1524. X        while (readhdr(&hdr, arc))    /* else extract all files */
  1525. X            extfile(&hdr, "", prt);
  1526. X
  1527. X    closearc(0);        /* close archive after reading */
  1528. X
  1529. X    if (note) {
  1530. X        for (n = 0; n < num; n++) {    /* report unused args */
  1531. X            if (!did[n]) {
  1532. X                printf("File not found: %s\n", arg[n]);
  1533. X                nerrs++;
  1534. X            }
  1535. X        }
  1536. X    }
  1537. X    free(name);
  1538. X}
  1539. X
  1540. Xvoid
  1541. Xextfile(hdr, path, prt)        /* extract a file */
  1542. X    struct heads   *hdr;    /* pointer to header data */
  1543. X    char           *path;    /* pointer to path name */
  1544. X    int             prt;    /* true if printing */
  1545. X{
  1546. X    FILE           *f, *fopen();    /* extracted file, opener */
  1547. X    char            buf[STRLEN];    /* input buffer */
  1548. X    char            fix[STRLEN];    /* fixed name buffer */
  1549. X    char           *i, *rindex();    /* string index */
  1550. X
  1551. X    if (prt) {        /* printing is much easier */
  1552. X        unpack(arc, stdout, hdr);    /* unpack file from archive */
  1553. X        printf("\f");    /* eject the form */
  1554. X        return;        /* see? I told you! */
  1555. X    }
  1556. X    strcpy(fix, path);    /* note path name template */
  1557. X#if    !MTS
  1558. X    if (*path) {
  1559. X    if (!(i = rindex(fix, '\\')))    /* find start of name */
  1560. X        if (!(i = rindex(fix, '/')))
  1561. X            if (!(i = rindex(fix, ':')))
  1562. X                i = fix - 1;
  1563. X    } else i = fix -1;
  1564. X#else
  1565. X    if (!(i = rindex(fix, sepchr[0])))
  1566. X        if (fix[0] != tmpchr[0])
  1567. X            i = fix - 1;
  1568. X        else
  1569. X            i = fix;
  1570. X#endif
  1571. X    strcpy(i + 1, hdr->name);    /* replace template with name */
  1572. X
  1573. X    if (note)
  1574. X        printf("Extracting file: %s\n", fix);
  1575. X
  1576. X    if (warn && !overlay) {
  1577. X        if (f = fopen(fix, "r")) {    /* see if it exists */
  1578. X                fclose(f);
  1579. X                printf("WARNING: File %s already exists!", fix);
  1580. X                fflush(stdout);
  1581. X                while (1) {
  1582. X                    printf("  Overwrite it (y/n)? ");
  1583. X                    fflush(stdout);
  1584. X                    fgets(buf, STRLEN, stdin);
  1585. X                    *buf = toupper(*buf);
  1586. X                    if (*buf == 'Y' || *buf == 'N')
  1587. X                        break;
  1588. X                }
  1589. X                if (*buf == 'N') {
  1590. X                    printf("%s not extracted.\n", fix);
  1591. X                    fseek(arc, hdr->size, 1);
  1592. X                    return;
  1593. X                }
  1594. X        }
  1595. X    }
  1596. X#if    !MTS
  1597. X    if (!(f = fopen(fix, "wb")))
  1598. X#else
  1599. X    {
  1600. X        fortran         create();
  1601. X        void        memset();
  1602. X        char            c_name[256];
  1603. X        struct crsize {
  1604. X            short           maxsize, cursize;
  1605. X        }               c_size;
  1606. X        char            c_vol[6];
  1607. X        int             c_type;
  1608. X        strcpy(c_name, fix);
  1609. X        strcat(c_name, " ");
  1610. X        c_size.maxsize = 0;
  1611. X        c_size.cursize = hdr->length / 4096 + 1;
  1612. X        memset(c_vol, 0, sizeof(c_vol));
  1613. X        c_type = 0x100;
  1614. X        create(c_name, &c_size, c_vol, &c_type);
  1615. X    }
  1616. X    if (image) {
  1617. X        f = fopen(fix, "wb");
  1618. X    } else
  1619. X        f = fopen(fix, "w");
  1620. X    if (!f)
  1621. X#endif
  1622. X    {
  1623. X        if (warn) {
  1624. X            printf("Cannot create %s\n", fix);
  1625. X            nerrs++;
  1626. X        }
  1627. X        fseek(arc, hdr->size, 1);
  1628. X        return;
  1629. X    }
  1630. X    /* now unpack the file */
  1631. X
  1632. X    unpack(arc, f, hdr);    /* unpack file from archive */
  1633. X    fclose(f);        /* all done writing to file */
  1634. X#if    !MTS
  1635. X    setstamp(fix, hdr->date, hdr->time);    /* use filename for stamp */
  1636. X#endif
  1637. X}
  1638. ________This_Is_The_END________
  1639. if test `wc -c < arcext.c` -ne     4898; then
  1640.     echo 'shar: arcext.c was damaged during transit (should have been     4898 bytes)'
  1641. fi
  1642. fi        ; : end of overwriting check
  1643. echo 'x - arcio.c'
  1644. if test -f arcio.c; then echo 'shar: not overwriting arcio.c'; else
  1645. sed 's/^X//' << '________This_Is_The_END________' > arcio.c
  1646. X/*
  1647. X * $Header: arcio.c,v 1.7 88/06/02 16:27:32 hyc Locked $
  1648. X */
  1649. X
  1650. X/*  ARC - Archive utility - ARCIO
  1651. X
  1652. X    Version 2.50, created on 04/22/87 at 13:25:20
  1653. X
  1654. X(C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
  1655. X
  1656. X    By:     Thom Henderson
  1657. X
  1658. X    Description:
  1659. X     This file contains the file I/O routines used to manipulate
  1660. X     an archive.
  1661. X
  1662. X    Language:
  1663. X     Computer Innovations Optimizing C86
  1664. X*/
  1665. X#include <stdio.h>
  1666. X#include "arc.h"
  1667. X#if    MTS
  1668. X#include <ctype.h>
  1669. X#endif
  1670. X
  1671. Xvoid    abort();
  1672. Xint    strlen(), free();
  1673. X
  1674. Xint
  1675. Xreadhdr(hdr, f)            /* read a header from an archive */
  1676. X    struct heads   *hdr;    /* storage for header */
  1677. X    FILE           *f;    /* archive to read header from */
  1678. X{
  1679. X#if    !MSDOS
  1680. X    unsigned char   dummy[28];
  1681. X    int             i;
  1682. X#endif
  1683. X    char            name[FNLEN];    /* filename buffer */
  1684. X    int             try = 0;/* retry counter */
  1685. X    static int      first = 1;    /* true only on first read */
  1686. X
  1687. X    if (!f)            /* if archive didn't open */
  1688. X        return 0;    /* then pretend it's the end */
  1689. X    if (feof(f))        /* if no more data */
  1690. X        return 0;    /* then signal end of archive */
  1691. X
  1692. X    if (fgetc(f) != ARCMARK) {    /* check archive validity */
  1693. X        if (warn) {
  1694. X            printf("An entry in %s has a bad header.", arcname);
  1695. X            nerrs++;
  1696. X        }
  1697. X        while (!feof(f)) {
  1698. X            try++;
  1699. X            if (fgetc(f) == ARCMARK) {
  1700. X                ungetc(hdrver = fgetc(f), f);
  1701. X                if (!(hdrver & 0x80) && hdrver <= ARCVER)
  1702. X                    break;
  1703. X            }
  1704. X        }
  1705. X
  1706. X        if (feof(f) && first)
  1707. X            abort("%s is not an archive", arcname);
  1708. X
  1709. X        if (changing && warn)
  1710. X            abort("%s is corrupted -- changes disallowed", arcname);
  1711. X
  1712. X        if (warn)
  1713. X            printf("  %d bytes skipped.\n", try);
  1714. X
  1715. X        if (feof(f))
  1716. X            return 0;
  1717. X    }
  1718. X    hdrver = fgetc(f);    /* get header version */
  1719. X    if (hdrver & 0x80)    /* sign bit? negative? */
  1720. X        abort("Invalid header in archive %s", arcname);
  1721. X    if (hdrver == 0)
  1722. X        return 0;    /* note our end of archive marker */
  1723. X    if (hdrver > ARCVER) {
  1724. X        fread(name, sizeof(char), FNLEN, f);
  1725. X#if    MTS
  1726. X        atoe(name, strlen(name));
  1727. X#endif
  1728. X        printf("I don't know how to handle file %s in archive %s\n",
  1729. X               name, arcname);
  1730. X        printf("I think you need a newer version of ARC.\n");
  1731. X        exit(1);
  1732. X    }
  1733. X    /* amount to read depends on header type */
  1734. X
  1735. X    if (hdrver == 1) {    /* old style is shorter */
  1736. X        fread(hdr, sizeof(struct heads) - sizeof(long int), 1, f);
  1737. X        hdrver = 2;    /* convert header to new format */
  1738. X        hdr->length = hdr->size;    /* size is same when not
  1739. X                         * packed */
  1740. X    } else
  1741. X#if    MSDOS
  1742. X        fread(hdr, sizeof(struct heads), 1, f);
  1743. X#else
  1744. X        fread(dummy, 27, 1, f);
  1745. X
  1746. X    for (i = 0; i < FNLEN; hdr->name[i] = dummy[i], i++);
  1747. X#if    MTS
  1748. X    (void) atoe(hdr->name, strlen(hdr->name));
  1749. X#endif
  1750. X    for (i = 0; i<4; hdr->size<<=8, hdr->size += dummy[16-i], i++);
  1751. X    hdr->date = (short) ((dummy[18] << 8) + dummy[17]);
  1752. X    hdr->time = (short) ((dummy[20] << 8) + dummy[19]);
  1753. X    hdr->crc = (short) ((dummy[22] << 8) + dummy[21]);
  1754. X    for (i = 0; i<4; hdr->length<<=8, hdr->length += dummy[26-i], i++);
  1755. X#endif
  1756. X
  1757. X    if (hdr->date > olddate
  1758. X        || (hdr->date == olddate && hdr->time > oldtime)) {
  1759. X        olddate = hdr->date;
  1760. X        oldtime = hdr->time;
  1761. X    }
  1762. X    first = 0;
  1763. X    return 1;        /* we read something */
  1764. X}
  1765. X
  1766. Xvoid
  1767. Xput_int(number, f)        /* write a 2 byte integer */
  1768. X    short           number;
  1769. X    FILE           *f;
  1770. X{
  1771. X    fputc((char) (number & 255), f);
  1772. X    fputc((char) (number >> 8), f);
  1773. X}
  1774. X
  1775. Xvoid
  1776. Xput_long(number, f)        /* write a 4 byte integer */
  1777. X    long            number;
  1778. X    FILE           *f;
  1779. X{
  1780. X    put_int((short) (number & 0xFFFF), f);
  1781. X    put_int((short) (number >> 16), f);
  1782. X}
  1783. X
  1784. Xvoid
  1785. Xwritehdr(hdr, f)        /* write a header to an archive */
  1786. X    struct heads   *hdr;    /* header to write */
  1787. X    FILE           *f;    /* archive to write to */
  1788. X{
  1789. X    fputc(ARCMARK, f);        /* write out the mark of ARC */
  1790. X    fputc(hdrver, f);    /* write out the header version */
  1791. X    if (!hdrver)        /* if that's the end */
  1792. X        return;        /* then write no more */
  1793. X#if    MSDOS
  1794. X    fwrite(hdr, sizeof(struct heads), 1, f);
  1795. X#else
  1796. X    /* byte/word ordering hassles... */
  1797. X#if    MTS
  1798. X    etoa(hdr->name, strlen(hdr->name));
  1799. X#endif
  1800. X    fwrite(hdr->name, 1, FNLEN, f);
  1801. X    put_long(hdr->size, f);
  1802. X    put_int(hdr->date, f);
  1803. X    put_int(hdr->time, f);
  1804. X    put_int(hdr->crc, f);
  1805. X    put_long(hdr->length, f);
  1806. X#endif
  1807. X
  1808. X    /* note the newest file for updating the archive timestamp */
  1809. X
  1810. X    if (hdr->date > arcdate
  1811. X        || (hdr->date == arcdate && hdr->time > arctime)) {
  1812. X        arcdate = hdr->date;
  1813. X        arctime = hdr->time;
  1814. X    }
  1815. X}
  1816. X
  1817. Xvoid
  1818. Xputc_tst(c, t)            /* put a character, with tests */
  1819. X    char            c;    /* character to output */
  1820. X    FILE           *t;    /* file to write to */
  1821. X{
  1822. X    c &= 0xff;
  1823. X    if (t)
  1824. X#if    UNIX
  1825. X        fputc(c, t);
  1826. X#else
  1827. X        if (fputc(c, t) == EOF)
  1828. X            abort("Write fail (disk full?)");
  1829. X#endif
  1830. X}
  1831. X
  1832. X/*
  1833. X * NOTE:  The filecopy() function is used to move large numbers of bytes from
  1834. X * one file to another.  This particular version has been modified to improve
  1835. X * performance in Computer Innovations C86 version 2.3 in the small memory
  1836. X * model.  It may not work as expected with other compilers or libraries, or
  1837. X * indeed with different versions of the CI-C86 compiler and library, or with
  1838. X * the same version in a different memory model.
  1839. X * 
  1840. X * The following is a functional equivalent to the filecopy() routine that
  1841. X * should work properly on any system using any compiler, albeit at the cost
  1842. X * of reduced performance:
  1843. X * 
  1844. X * filecopy(f,t,size) 
  1845. X *      FILE *f, *t; long size; 
  1846. X * { 
  1847. X *      while(size--)
  1848. X *              putc_tst(fgetc(f),t); 
  1849. X * }
  1850. X */
  1851. X#if    MSDOS
  1852. X#include <fileio2.h>
  1853. X
  1854. Xfilecopy(f, t, size)        /* bulk file copier */
  1855. X    FILE           *f, *t;    /* files from and to */
  1856. X    long            size;    /* bytes to copy */
  1857. X{
  1858. X    char           *buf;    /* buffer pointer */
  1859. X    char           *alloc();/* buffer allocator */
  1860. X    unsigned int    bufl;    /* buffer length */
  1861. X    unsigned int    coreleft();    /* space available reporter */
  1862. X    unsigned int    cpy;    /* bytes being copied */
  1863. X    long            floc, tloc, fseek();    /* file pointers, setter */
  1864. X    struct regval   reg;    /* registers for DOS calls */
  1865. X
  1866. X    if ((bufl = coreleft()) < 1000)    /* see how much space we have */
  1867. X        abort("Out of memory");
  1868. X    bufl -= 1000;        /* fudge factor for overhead */
  1869. X    if (bufl > 60000)
  1870. X        bufl = 60000;    /* avoid choking alloc() */
  1871. X    if (bufl > size)
  1872. X        bufl = size;    /* avoid wasting space */
  1873. X    buf = alloc(bufl);    /* allocate our buffer */
  1874. X
  1875. X    floc = fseek(f, 0L, 1);    /* reset I/O system */
  1876. X    tloc = fseek(t, 0L, 1);
  1877. X
  1878. X    segread(®.si);    /* set segment registers for DOS */
  1879. X
  1880. X    while (size > 0) {    /* while more to copy */
  1881. X        reg.ax = 0x3F00;/* read from handle */
  1882. X        reg.bx = filehand(f);
  1883. X        reg.cx = bufl < size ? bufl : size;    /* amount to read */
  1884. X        reg.dx = buf;
  1885. X        if (sysint21(®, ®) & 1)
  1886. X            abort("Read fail");
  1887. X
  1888. X        cpy = reg.ax;    /* amount actually read */
  1889. X        reg.ax = 0x4000;/* write to handle */
  1890. X        reg.bx = filehand(t);
  1891. X        reg.cx = cpy;
  1892. X        reg.dx = buf;
  1893. X        sysint21(®, ®);
  1894. X
  1895. X        if (reg.ax != cpy)
  1896. X            abort("Write fail (disk full?)");
  1897. X
  1898. X        size -= (long) cpy;
  1899. X    }
  1900. X
  1901. X    free(buf);        /* all done with buffer */
  1902. X}
  1903. X#else
  1904. X
  1905. Xvoid
  1906. Xfilecopy(f, t, size)        /* bulk file copier */
  1907. X    FILE           *f, *t;    /* files from and to */
  1908. X    long            size;    /* bytes to copy */
  1909. X{
  1910. X    char           *buf;    /* buffer pointer */
  1911. X    char           *malloc();    /* buffer allocator */
  1912. X    unsigned int    bufl;    /* buffer length */
  1913. X    unsigned int    cpy;    /* bytes being copied */
  1914. X
  1915. X    bufl = 32760;
  1916. X    if (bufl > size)
  1917. X        bufl = size;    /* don't waste space */
  1918. X
  1919. X    buf = malloc(bufl);
  1920. X
  1921. X    while (size > 0) {
  1922. X        cpy = fread(buf, sizeof(char),
  1923. X            bufl < size ? bufl : (unsigned short) size, f);
  1924. X        if (fwrite(buf, sizeof(char), cpy, t) != cpy)
  1925. X            abort("Write fail (no space?)");
  1926. X        size -= cpy;
  1927. X    }
  1928. X
  1929. X    free(buf);
  1930. X}
  1931. X#endif
  1932. ________This_Is_The_END________
  1933. if test `wc -c < arcio.c` -ne     7418; then
  1934.     echo 'shar: arcio.c was damaged during transit (should have been     7418 bytes)'
  1935. fi
  1936. fi        ; : end of overwriting check
  1937. echo 'x - arclst.c'
  1938. if test -f arclst.c; then echo 'shar: not overwriting arclst.c'; else
  1939. sed 's/^X//' << '________This_Is_The_END________' > arclst.c
  1940. X/*
  1941. X * $Header: arclst.c,v 1.5 88/06/01 18:05:57 hyc Locked $
  1942. X */
  1943. X
  1944. X/*  ARC - Archive utility - ARCLST
  1945. X  
  1946. X    Version 2.39, created on 04/22/87 at 13:48:29
  1947. X  
  1948. X(C) COPYRIGHT 1985-87 by System Enhancement Associates; ALL RIGHTS RESERVED
  1949. X  
  1950. X    By:     Thom Henderson
  1951. X  
  1952. X    Description:
  1953. X     This file contains the routines used to list the contents
  1954. X     of an archive.
  1955. X  
  1956. X    Language:
  1957. X     Computer Innovations Optimizing C86
  1958. X*/
  1959. X#include <stdio.h>
  1960. X#include "arc.h"
  1961. X
  1962. Xvoid            rempath(), openarc(), closearc();
  1963. Xint             readhdr(), match();
  1964. X
  1965. Xvoid
  1966. Xlstarc(num, arg)        /* list files in archive */
  1967. X    int             num;    /* number of arguments */
  1968. X    char           *arg[];    /* pointers to arguments */
  1969. X{
  1970. X    struct heads    hdr;    /* header data */
  1971. X    int             list;    /* true to list a file */
  1972. X    int             did[MAXARG];    /* true when argument was used */
  1973. X    long            tnum, tlen, tsize;    /* totals */
  1974. X    int             n;    /* index */
  1975. X    void            lstfile();
  1976. X
  1977. X    tnum = tlen = tsize = 0;/* reset totals */
  1978. X
  1979. X    for (n = 0; n < num; n++)    /* for each argument */
  1980. X        did[n] = 0;    /* reset usage flag */
  1981. X    rempath(num, arg);    /* strip off paths */
  1982. X
  1983. X    if (note && !kludge) {
  1984. X        printf("Name          Length  ");
  1985. X        if (bose)
  1986. X            printf("  Stowage    SF   Size now");
  1987. X        printf("  Date     ");
  1988. X        if (bose)
  1989. X            printf("  Time    CRC");
  1990. X        printf("\n");
  1991. X
  1992. X        printf("============  ========");
  1993. X        if (bose)
  1994. X            printf("  ========  ====  ========");
  1995. X        printf("  =========");
  1996. X        if (bose)
  1997. X            printf("  ======  ====");
  1998. X        printf("\n");
  1999. X    }
  2000. X    openarc(0);        /* open archive for reading */
  2001. X
  2002. X    if (num) {        /* if files were named */
  2003. X        while (readhdr(&hdr, arc)) {    /* process all archive files */
  2004. X            list = 0;    /* reset list flag */
  2005. X            for (n = 0; n < num; n++) {    /* for each template
  2006. X                             * given */
  2007. X                if (match(hdr.name, arg[n])) {
  2008. X                    list = 1;    /* turn on list flag */
  2009. X                    did[n] = 1;    /* turn on usage flag */
  2010. X                    break;    /* stop looking */
  2011. X                }
  2012. X            }
  2013. X
  2014. X            if (list) {    /* if this file is wanted */
  2015. X                if (!kludge)
  2016. X                    lstfile(&hdr);    /* then tell about it */
  2017. X                tnum++;    /* update totals */
  2018. X                tlen += hdr.length;
  2019. X                tsize += hdr.size;
  2020. X            }
  2021. X            fseek(arc, hdr.size, 1);    /* move to next header */
  2022. X        }
  2023. X    } else
  2024. X        while (readhdr(&hdr, arc)) {    /* else report on all files */
  2025. X            if (!kludge)
  2026. X                lstfile(&hdr);
  2027. X            tnum++;    /* update totals */
  2028. X            tlen += hdr.length;
  2029. X            tsize += hdr.size;
  2030. X            fseek(arc, hdr.size, 1);    /* skip to next header */
  2031. X        }
  2032. X
  2033. X    closearc(0);        /* close archive after reading */
  2034. X
  2035. X    if (note && !kludge) {
  2036. X        printf("        ====  ========");
  2037. X        if (bose)
  2038. X            printf("            ====  ========");
  2039. X        printf("\n");
  2040. X    }
  2041. X    if (note) {
  2042. X        printf("Total %6ld  %8ld", tnum, tlen);
  2043. X        if (bose) {
  2044. X            if (tlen)
  2045. X                printf("            %3ld%%", 100L - (100L * tsize) / tlen);
  2046. X            else
  2047. X                printf("            ---");
  2048. X            printf("  %8ld", tsize);
  2049. X        }
  2050. X        printf("\n");
  2051. X
  2052. X        for (n = 0; n < num; n++) {    /* report unused args */
  2053. X            if (!did[n]) {
  2054. X                printf("File not found: %s\n", arg[n]);
  2055. X                nerrs++;
  2056. X            }
  2057. X        }
  2058. X    }
  2059. X}
  2060. X
  2061. Xvoid
  2062. Xlstfile(hdr)            /* tell about a file */
  2063. X    struct heads   *hdr;    /* pointer to header data */
  2064. X{
  2065. X    int             yr, mo, dy;    /* parts of a date */
  2066. X    int             hh, mm;    /* parts of a time */
  2067. X
  2068. X    static char    *mon[] =    /* month abbreviations */
  2069. X    {
  2070. X     "Jan", "Feb", "Mar", "Apr",
  2071. X     "May", "Jun", "Jul", "Aug",
  2072. X     "Sep", "Oct", "Nov", "Dec"
  2073. X    };
  2074. X
  2075. X    if (!note) {        /* no notes means short listing */
  2076. X        printf("%s\n", hdr->name);
  2077. X        return;
  2078. X    }
  2079. X
  2080. X    yr = (hdr->date >> 9) & 0x7f;    /* dissect the date */
  2081. X    mo = (hdr->date >> 5) & 0x0f;
  2082. X    dy = hdr->date & 0x1f;
  2083. X
  2084. X    hh = (hdr->time >> 11) & 0x1f;    /* dissect the time */
  2085. X    mm = (hdr->time >> 5) & 0x3f;
  2086. X/*    ss = (hdr->time & 0x1f) * 2;    seconds, not used. */
  2087. X
  2088. X    printf("%-12s  %8ld  ", hdr->name, hdr->length);
  2089. X
  2090. X    if (bose) {
  2091. X        switch (hdrver) {
  2092. X        case 1:
  2093. X        case 2:
  2094. X            printf("   --   ");
  2095. X            break;
  2096. X        case 3:
  2097. X            printf(" Packed ");
  2098. X            break;
  2099. X        case 4:
  2100. X            printf("Squeezed");
  2101. X            break;
  2102. X        case 5:
  2103. X        case 6:
  2104. X        case 7:
  2105. X            printf("crunched");
  2106. X            break;
  2107. X        case 8:
  2108. X            printf("Crunched");
  2109. X            break;
  2110. X        case 9:
  2111. X            printf("Squashed");
  2112. X            break;
  2113. X        default:
  2114. X            printf("Unknown!");
  2115. X        }
  2116. X
  2117. X        if (hdr->length)
  2118. X            printf("  %3ld%%", 100L - (100L * hdr->size) / hdr->length);
  2119. X        else
  2120. X            printf("  ---");
  2121. X        printf("  %8ld  ", hdr->size);
  2122. X    }
  2123. X    printf("%2d %3s %02d", dy, mon[mo - 1], (yr + 80) % 100);
  2124. X
  2125. X    if (bose)
  2126. X        printf("  %2d:%02d%c  %04x",
  2127. X               (hh > 12 ? hh - 12 : hh), mm, (hh > 11 ? 'p' : 'a'),
  2128. X               hdr->crc & 0xffff);
  2129. X
  2130. X    printf("\n");
  2131. X}
  2132. ________This_Is_The_END________
  2133. if test `wc -c < arclst.c` -ne     4418; then
  2134.     echo 'shar: arclst.c was damaged during transit (should have been     4418 bytes)'
  2135. fi
  2136. fi        ; : end of overwriting check
  2137. exit 0
  2138.  
  2139. -- 
  2140. Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.
  2141.  
  2142.  
  2143.